import { MockMethod } from 'vite-plugin-mock'
const baseUrl = '/viteApp/api/mock';
import { Decrypt } from '../../src/utils'
export default [
	{
		url: baseUrl + "/login",
		method: "post",
		response: (e) => {
			const params = e.body ? e.body : ""
			let { username, password, uuid } = params
			let decryptWord = Decrypt(password, uuid.slice(0, 16), uuid.slice(uuid.length - 16, uuid.length))
			if (password && decryptWord !== '123wer!@') {
				return {
					code: 1,
					message: "err",
					data: "输入的密码错误"
				}
			} else if (username && password && uuid) {
				return {
					code: 0,
					message: "登录成功",
					data: {
						username,
						password,
						uuid,
						userInfo:{
							nickName:"提子吐司张女士",
							ID:"1092348293479",
							integration:"32"
						},
						userAccountList:[{
							text:"红包",
							quantitation:"218"
						},{
							text:"优惠券",
							quantitation:"12张"
						},{
							text:"鲜豆",
							quantitation:"88"
						},{
							text:"白条",
							quantitation:"1000"
						}],
						userConfigList:[{
							iconName:"paywait",
							iconBg:"#ed4a47",
							configName:"我的钱包"
						},{
							iconName:"address",
							iconBg:"#32C5FF",
							configName:"我的地址"
						},{
							iconName:"peoples",
							iconBg:"#9937FE",
							configName:"客服与帮助"
						}]
					}
				}
			} else {
				return {
					code: 1,
					message: "err",
					data: "登录失败"
				}
			}
		}
	},
	{
		url: baseUrl + "/smsCode",
		method: "post",
		response: (e) => {
			const params = e.body ? e.body : ""
			let { username, uuid } = params
			function getRandomSixDigit() {
				let code = ''
				for (var i = 0; i < 6; i++) {
					code += parseInt(Math.random() * 10)
				}
				return code
			}
			if (username && uuid) {
				return {
					code: 0,
					message: "验证码发送成功",
					data: {
						smsCode: getRandomSixDigit(),
						smsSqe: getRandomSixDigit()
					}
				}
			} else {
				return {
					code: 1,
					message: "err",
					data: "验证码发送失败"
				}
			}
		}
	},
	{
		url: baseUrl + "/register",
		method: "post",
		response: (e) => {
			const params = e.body ? e.body : ""
			let { username, password,passwordsed,smsCode,smsSqe, uuid } = params
			let decryptWord = Decrypt(password, uuid.slice(0, 16), uuid.slice(uuid.length - 16, uuid.length))
			let decryptWord2 = Decrypt(passwordsed, uuid.slice(0, 16), uuid.slice(uuid.length - 16, uuid.length))
			if (decryptWord!==decryptWord2) {
				return {
					code: 1,
					message: "err",
					data: "两次输入的密码错误"
				}
			} else if (username && password && smsCode&&smsSqe) {
				let userInfo ={
					username:"张三",
					iphone:"135123456",
					location:"上海",
					integration:400,
					userId:"uId1234567"
				}
				return {
					code: 0,
					message: "注册成功",
					data: {
						userInfo,...params
					}
				}
			} else {
				return {
					code: 1,
					message: "err",
					data: "登录失败"
				}
			}
		}
	},
	{
		url: baseUrl + "/userInfo",
		method: "get",
		response: (e) => {
			return {
				code: 0,
				message: "success",
				data: {
					userInfo:{
						nickName:"提子吐司张女士",
						ID:"1092348293479",
						integration:"32"
					},
					userAccountList:[{
						text:"红包",
						quantitation:"218"
					},{
						text:"优惠券",
						quantitation:"12张"
					},{
						text:"鲜豆",
						quantitation:"88"
					},{
						text:"白条",
						quantitation:"1000"
					}],
					userConfigList:[{
						iconName:"paywait",
						iconBg:"#ed4a47",
						configName:"我的钱包"
					},{
						iconName:"address",
						iconBg:"#32C5FF",
						configName:"我的地址"
					},{
						iconName:"peoples",
						iconBg:"#9937FE",
						configName:"客服与帮助"
					}]
				}
			}
		}
	}
] as MockMethod[]